import { RouteConfig } from "vue-router";
import { addRoutesConfig } from ".";
import { RouteMeta } from "./routeMeta";

export enum homeType { //主页入口类型类型
  SYS = "system", // 系统角色
  USER = "user" // 普通用户
}

export const userHomeRoutes: RouteConfig[] = [
  // 入口 普通用户主页
  {
    path: "/",
    component: () => import("@/layout/front/index.vue"),
    // component: homeLayout,
    redirect: "/home",
    meta: new RouteMeta({
      title: "首页",
      menuKey: "root"
    }),
    children: [
      {
        path: "home",
        component: () => import("@/views/frontHome.vue"),
        meta: new RouteMeta({
          title: "首页",
          menuKey: "home",
          parentKeys: ["root"],
          icon: "dashboard",
          breadcrumb: false
        })
      }
      // {
      //   path: "child/*",
      //   component: () => import("@/qiankun/components/childapp.vue"),
      //   meta: {
      //     title: "子应用",
      //     defaultPath:"child/app1",
      //     alwaysShow: false
      //   }
      // }
    ]
  }
];

export const sysHomeRoutes: RouteConfig[] = [
  // 入口 系统用户主页
  {
    path: "/",
    component: () => import("@/layout/back/index.vue"),
    // component: homeLayout,
    redirect: "/home",
    meta: new RouteMeta({
      title: "首页",
      menuKey: "root"
    }),
    children: [
      {
        path: "home",
        component: () => import("@/views/backHome.vue"),
        meta: new RouteMeta({
          title: "首页",
          menuKey: "home",
          parentKeys: ["root"],
          icon: "dashboard",
          breadcrumb: false
        })
      }
      // {
      //   path: "child/*",
      //   component: () => import("@/qiankun/components/childapp.vue"),
      //   meta: {
      //     title: "子应用",
      //     defaultPath:"child/app1",
      //     alwaysShow: false
      //   }
      // }
    ]
  }
];

export function addHomeEntryRoutes(type: homeType | string) {
  // 动态添加主页入口路由
  if (type == homeType.USER) addRoutesConfig(userHomeRoutes);
  else if (type == homeType.SYS) addRoutesConfig(sysHomeRoutes);
  // throw new Error("没有该路由")
  else addRoutesConfig(userHomeRoutes);
}
